<?php
namespace Home\Controller;
/**
 * 域名交易记录
 * @author Administrator
 *
 */
class TranslogController extends HomeBaseController
{
    public function index(){
        if(session('uid')==null){
            $this->ajaxReturn(array('code'=>'error','info' => '请选去登录！'));//0错误，1成功
            exit();
        }
        
        $page=I('page',1);
        $size=10;
        $start=($page-1)*$size;
        $cond['_logic'] = 'OR';
        $cond['a.buyerid']=session('uid');
        $cond['a.sellerid']=session('uid');
        $wher['_complex'] = $cond;
        $category=I('category','');
        if($category!=''){
            $wher['a.domain_type_id']=$category;
        }
        $duration=I('duration','');
        
        if($duration!=''){
            if($duration==1){
                $wher['a.createdate']=array(array('egt',date("Y-m-d").' 00:00:00'),array('elt',date("Y-m-d").' 23:59:59'));
            }else {
                $wher['a.createdate']=array(array('egt',date("Y-m-d",strtotime("-".$duration." day")).' 00:00:00'),array('elt',date("Y-m-d").' 23:59:59'));
            }
        }
        $daolog=D('DomainTranslog');
        $list = $daolog->join(' as a left join dd_domain_type b on a.domain_type_id=b.id ')->
        field('a.id,a.buyerid,a.sellerid,a.trans_number,a.price,a.totel_price,a.trans_fee,a.actual_price,a.createdate,b.name')
        ->where($wher)->order('a.createdate desc' )->limit($start,$size)->select();
        
        $count = $daolog->join('as a left join dd_domain_type b on a.domain_type_id=b.id')->where($wher)->count();
        //交易金额
        $trade=0;
        foreach($list as $k=>$val){
            $trade = $trade+$val['actual_price'];
        };
        
        $this->assign('list', $list);
        $this->assign('category', I('post.category',0));
        $this->assign('duration', I('post.duration',0));
        $this->assign('count', $count);
        $this->assign('page', $page);
        $this->assign('pageNum', $count%$size);
        $this->assign('trade', $trade);
        $this->display('translog/index');
    }
    
    public function getDomainTypeList(){
            $list = M('domain_type')->select();
            $this->ajaxReturn($list,'JSON');
    }
}